import java.io.InputStream;
import java.io.PrintWriter;

public class PetServlet implements Servlet{
    @Override
    public void doGet(Request request, Response response) throws Exception {
        System.out.println("legs     "+request.getParameter("legs").trim());
        System.out.println("weight   "+request.getParameter("weight").trim());
        int legs= Integer.parseInt(request.getParameter("legs").trim());
        int weight= Integer.parseInt(request.getParameter("weight").trim());
        String pet=null;
        if (legs == 0) {
            request.setAttribute("pet", "a goldfish");

        } else {
            if (legs == 4) {
                if (weight < 20) {
                    request.setAttribute("pet", "a cat");
                    pet="a cat";
                }

                if (weight < 100) {
                    request.setAttribute("pet", "a dog");
                    pet="a dog";
                }
            }
            request.setAttribute("pet", "a house plant");
            pet="a house plant";
        }

        response.print("<html> <body> <h1>Recommended Pet - Testing for Servlet</h1> <p>\n"
        +"You want a " + legs + "-legged pet weighing " + weight + "lbs.\n"
        +"<P> We recommend getting <b>" + pet+"\n"
        +"</b> <hr> </body> </html> ");
    }

    @Override
    public void doPost(Request request, Response response) throws Exception {
        doGet(request,response);
    }
}
